//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Microsoft.Research.ScientificWorkflow
{
    /// <summary>
    /// Attribute attached to workflows and workflow parameters that allows
    /// setting both a name and a label. The name represents a quick, human
    /// readable description of the activity. Examples might include:
    /// -> 'Xml Parser'
    /// -> 'Web Page Downloader'
    /// -> 'Salinity Level Filter'
    /// 
    /// For a more complete description, please use the DescriptionAttribute.
    /// 
    /// The label property is meant as an optional name that is more terse
    /// and thus more presentable in a compact user interface environment.
    /// Thus for example 'Salinity Level Filter' might have as its label
    /// 'Salinity Filter' or even 'Salinity'.
    /// 
    /// For user interface considerations an expanded tooltip would likely
    /// use the name and description attributes, while a visual representation
    /// of an entire workflow would just use the label.
    /// 
    /// When no label is specified or when the label is empty, the name is
    /// returned when the Label property is querried. Thus it is not necessary
    /// to specify a label when you want the label to match the name.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = false)]
    public class NameAttribute : Attribute
    {
        private string name;
        private string label;
        private string displayLabel;

        /// <summary>
        /// Create a name attribute with just a Name property. The Label
        /// property will match the Name.
        /// </summary>
        public NameAttribute(string name)
        {
            this.name = name;
        }

        /// <summary>
        /// Create a name attribute with both a name and a label.
        /// </summary>
        /// <returns></returns>
        public NameAttribute(string name, string label)
        {
            this.name = name;
            this.label = label;
        }

        /// <summary>
        /// Create a name attribute with both a name and a label.
        /// </summary>
        /// <returns></returns>
        public NameAttribute(string name, string label, string displayLabel)
        {
            this.name = name;
            this.label = label;
            this.displayLabel = displayLabel;
        }

        /// <summary>
        /// A short but descriptive name for the workflow or workflow activity.
        /// </summary>
        public string Name
        {
            get { return name; }
        }

        /// <summary>
        /// A short name for the workflow or workflow activity that is appropriate
        /// for use in small spaces within a graphical user interface.
        /// </summary>
        public string Label
        {
            get
            {
                if (String.IsNullOrEmpty(label))
                    return Name;
                return label;
            }
        }

        /// <summary>
        /// Gets the display label.
        /// </summary>
        /// <value>The display label.</value>
        public string DisplayLabel
        {
            get
            {
                if (String.IsNullOrEmpty(displayLabel))
                    return Label;
                return displayLabel;
            }
        }
    }

    /// <summary>
    /// The category attribute is applicable to workflow activities.
    /// It defines which category to associate a particular workflow
    /// item with. Activities may have more than one category. The
    /// categories themselves are defined using a string path through
    /// the category heirarchy. This path uses the ID of the categories
    /// to identify a category.
    /// 
    /// For example:
    /// 
    /// [Category("Data/Xml")]
    /// [Category("Data/Streams"]
    /// public class XmlDocumentReader : Activity ...
    /// 
    /// If the category is not found in the know category tree it will be
    /// assigned to an uncategorized group.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
    public class WorkflowCategoryAttribute : Attribute
    {
        private string path;

        /// <summary>
        /// Defines a category on a workflow item by passing in a path
        /// representing a place in the tree of known categories.
        /// </summary>
        /// <param name="path"></param>
        public WorkflowCategoryAttribute(string path)
        {
            this.path = path;
        }

        public string Path
        {
            get { return path; }
        }
    }


    /// <summary>
    /// The ActivityHiddenAttribute attribute is applicable to workflow activities.
    /// It defines whether the activity needs to be displayed in the Left pane to the User
    /// 
    /// If the HiddenAttribute is not found in the know category tree it will be
    /// assigned to an Visiblity group.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
    public class HideActivityAttribute : Attribute
    {
        private bool hide = false;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="hideActivity">Hide the activity if true, Displays otherwise </param>
        public HideActivityAttribute(bool hideActivity)
        {
            this.hide = hideActivity;
        }

        /// <summary>
        /// Get the hide flag
        /// </summary>
        public bool HideActivity
        {
            get
            {
                return this.hide;
            }
        }
    }
}
